﻿using System.Diagnostics;
using ResPackClient.DataBase;
using System.Windows;

namespace ResPackClient
{
    /// <summary>
    /// Interaction logic for DeleteWorkSpace.xaml
    /// </summary>
    public partial class DeleteRow : Window
    {
        /// <summary>
        /// Constructeur init. pour WorkSpace
        /// </summary>
        /// <param name="table">La table contenant les répertoires</param>
        public DeleteRow(ResPackDataSet.tbWorkSpaceDataTable table)
        {
            Debug.Assert(table != null);

            InitializeComponent();
            _cbDelete.DataContext = table;
            _cbDelete.ItemTemplate = (DataTemplate)ResPackApp.Current.Resources["DATA_TEMPLATE_WORKSPACE"];
        }
        /// <summary>
        ///  Constructeur init. pour Families
        /// </summary>
        /// <param name="table">La table contenant les familles</param>
        public DeleteRow(ResPackDataSet.tbResourceFamiliesDataTable table)
        {
            Debug.Assert(table != null);

            InitializeComponent();
            _cbDelete.DataContext = table;
            _cbDelete.ItemTemplate = (DataTemplate)ResPackApp.Current.Resources["DATA_TEMPLATE_FAMILY"];
        }
        /// <summary>
        ///  Constructeur init. pour Types
        /// </summary>
        /// <param name="table">La table contenant les types</param>
        public DeleteRow(ResPackDataSet.tbResourceTypesDataTable table)
        {
            Debug.Assert(table != null);

            InitializeComponent();
            _cbDelete.DataContext = table;
            _cbDelete.ItemTemplate = (DataTemplate)ResPackApp.Current.Resources["DATA_TEMPLATE_TYPE"];
        }
        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void OnOk(object sender, RoutedEventArgs e)
        {
            DialogResult = true;
            this.Close();
        }
        /// <summary>
        /// Clef primaire.
        /// </summary>
        public int PrimaryKey
        {
            get
            {
                Debug.Assert(_cbDelete.SelectedIndex > -1);

                if (_cbDelete.DataContext.GetType() == typeof(ResPackDataSet.tbWorkSpaceDataTable))
                {
                    return ((ResPackDataSet.tbWorkSpaceRow)_cbDelete.SelectedItem).PK_ID;
                }
                else if (_cbDelete.DataContext.GetType() == typeof(ResPackDataSet.tbResourceFamiliesDataTable))
                {
                    return ((ResPackDataSet.tbResourceFamiliesRow)_cbDelete.SelectedItem).PK_ID;
                }
                else if (_cbDelete.DataContext.GetType() == typeof(ResPackDataSet.tbResourceTypesDataTable))
                {
                    return ((ResPackDataSet.tbResourceTypesRow)_cbDelete.SelectedItem).PK_ID;
                }

                return -1;
            }
        }

    }
}
